num1 = int(input())
if num1 % 1 > 0 or num1 < 1000 or num1 > 9999:
    print('0')
    exit() 
num1 = str(num1) 
slices = [int(num1[0:2]), int(num1[1:3]), int(num1[2:4]),
          int(num1[0:3]), int(num1[1:4]),
          int(num1[0:4])] 
num1 = int(num1) 
answer = 0  
for slice in slices:  
    prime = True
    for div in range(2, int(slice**0.5)+1): 
        if slice % div == 0: 
            prime = False
            break 
    if prime:
        answer = max(answer, slice) 
print(answer) 